<?php

namespace App\Models\Traits;

use App\Models\Originurl as Origin;

use App\Jobs\CrawlerOriginUrls;

trait CrawlerOriginUrlHelper
{
    // 存放起始网址数组
    protected $originUrls = [];


    // 抓取地址
    public function crawlerOriginUrl($domain = '')
    {
        $where = [];
        if (!empty($domain)) {
            $where[] = ['domain', '=', (string) $domain];
        }
        $where[] = ['status', '=', 1];
        $originUrls = Origin::where($where)->has('filter')->get();
        // 推送抓取队列
        foreach($originUrls as $v) {
            dispatch(new CrawlerOriginUrls($v));
        }
        return $originUrls;
    }
}
